Skip to content

Method: of(int, int)

1: package de.fhdw.gaming.ipspiel22.vierGewinnt.domain;
2:
3: /**
4: * Represents a field position on a board. It contains a column number and a row number.
5: */
6: public final class VGPosition {
7:
8: /**
9: * The column index.
10: */
11: private final int column;
12: /**
13: * The column index.
14: */
15: private final int row;
16:
17: /**
18: * Creates a position on an VG board.
19: *
20: * @param column The column number.
21: * @param row The row number.
22: */
23: public VGPosition(final int column, final int row) {
24: this.column = column;
25: this.row = row;
26: }
27:
28: /**
29: * Creates a position on an VG board.
30: *
31: * @param column The column number.
32: * @param row The row number.
33: * @return The position.
34: */
35: public static VGPosition of(final int column, final int row) {
36: return new VGPosition(column, row);
37: }
38:
39: /**
40: * Returns the column number.
41: */
42: public int getColumn() {
43: return this.column;
44: }
45:
46: /**
47: * Returns the row number.
48: */
49: public int getRow() {
50: return this.row;
51: }
52:
53: @Override
54: public String toString() {
55: return String.format("%c%d", (char) (this.row + 'A'), this.column + 1);
56: }
57:
58: @Override
59: public int hashCode() {
60: return this.column ^ this.row;
61: }
62:
63: @Override
64: public boolean equals(final Object obj) {
65: if (obj instanceof VGPosition) {
66: final VGPosition other = (VGPosition) obj;
67: return this.column == other.column && this.row == other.row;
68: }
69: return false;
70: }
71: }